package behavioralpattern.mediatorpattern;
/**
 * 邢帅教育
 * <p>
 * 本源代码由数据中心及其作者共同所有，未经版权持有者的事先书面授权，
 * 不得使用、复制、修改、合并、发布、分发和/或销售本源代码的副本。
 *
 * @copyright Copyright (c) 2018. xsteach.com all rights reserved.
 */

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
 * @author maikec
 * @date 2018/9/13
 */
public abstract class Mediator {
    protected volatile Set<Colleague> colleagues;
    /**
     * 调停同事类之间交互
     * @param msg
     * @param colleague 消息接收对象
     */
    public abstract void mediate(String msg, Colleague colleague);
    public void register(Colleague colleague) {
        if (Objects.isNull(colleagues)) {
            colleagues = new HashSet<Colleague>(  );
        }
        colleagues.add( colleague );
        colleague.setMediator( this );
    }
}
